package com.xiaobai.netease_news.utils;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by Android Studio
 * Project: NeteaseNews
 * Author: Jack
 * Email: jackfangqi1314@gmail.com/jackfangqi@163.com
 * Date: 2015/6/3
 */
public class StreamUtil {
    private StreamUtil() {
    }

    public static byte[] readStream(InputStream inputStream) throws IOException {
        byte[] data = null;
        if (inputStream != null) {
            byte[] buf = new byte[1024];
            int len;
            ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
            while (true) {
                len = inputStream.read(buf);
                if (len == -1)
                    break;

                arrayOutputStream.write(buf, 0, len);
            }

            data = arrayOutputStream.toByteArray();
            buf = null;
            arrayOutputStream.close();
        }
        return data;
    }
}
